package cn.codeforfun.gitee.starter;

import cn.codeforfun.gitee.api.GiteeService;
import cn.codeforfun.gitee.api.GiteeServiceImpl;
import cn.codeforfun.gitee.config.GiteeConfigStorage;
import cn.codeforfun.gitee.config.impl.GiteeConfigStorageImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author wangbin
 */
@Configuration
public class GiteeStarterConfiguration {
    @Resource
    private GiteeProperties giteeProperties;

    @Bean
    @ConditionalOnMissingBean
    public GiteeService giteeService() {
        GiteeConfigStorage configStorage = new GiteeConfigStorageImpl();
        configStorage.setClientId(giteeProperties.getClientId());
        configStorage.setClientSecret(giteeProperties.getClientSecret());
        configStorage.setUsername(giteeProperties.getUsername());
        configStorage.setPassword(giteeProperties.getPassword());

        GiteeService service = new GiteeServiceImpl();
        service.setGiteeConfigStorage(configStorage);
        return service;
    }
}
